package com.wfh.picture.config;

import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author FengHuan Wang
 * @Date 2025/5/13 9:01
 * @Version 1.0
 */
@Configuration
@ConfigurationProperties(prefix = "redisson")
@Data
public class RedissonConfig {

    private String password;

    private String host;

    private Integer port;

    private Integer database = 0;

    @Bean
    public RedissonClient redissonClient(){
        Config config = new Config();
        config.useSingleServer()
                .setAddress(String.format("redis://%s:%s", host, port))
                .setDatabase(database)
                .setPassword(password);
        return Redisson.create(config);
    }
}
